<?php
declare (strict_types = 1);

namespace app\api\controller\v1;

use app\api\controller\Base;
use app\api\model\DomainsRolesRelation as DomainsRolesRelationModel;
use app\Request;

class DomainsRolesRelation extends Base
{

    /**
     * 角色域绑定关系列表
     * @param $page //页面
     * @param $pagesize //每页大小
     * @return \think\response\Json
     */
    public function domainsroleslist($page,$pagesize){
        try {
            $DomainsRolesRelationModel = new DomainsRolesRelationModel();
            $list = $DomainsRolesRelationModel->DomainsRolesList($page,$pagesize);
            return json($list);
        } catch (\Exception $e) {
            $error = ['status'=>false,'code'=>$e->getCode(),'msg'=>$e->getMessage(),'data'=>''];
            return json($error);
        }
    }
     /**
     * 已绑定角色列表
     * @param $page
     * @param $pagesize
     * @return \think\response\Json
     */
    public function boundroleslist($page,$pagesize){
        try {
            $DomainsRolesRelationModel = new DomainsRolesRelationModel();
            $list = $DomainsRolesRelationModel->boundroleslist($page,$pagesize);
            return json($list);
        } catch (\Exception $e) {
            $error = ['status'=>false,'code'=>$e->getCode(),'msg'=>$e->getMessage(),'data'=>''];
            return json($error);
        }
    }
    /**
     * 新增角色域绑定关系
     * @param $domains_id  //域id
     * @param $roles_id //角色id
     * @param int $status //状态
     * @return \think\response\Json
     */
    public function domainsrolesadd($domains_id,$roles_id,$status=1){
        try {
            $DomainsRolesRelationModel = new DomainsRolesRelationModel();
            $res = $DomainsRolesRelationModel->DomainsRolesAdd($domains_id,$roles_id,$status);
            return json($res);
        } catch (\Exception $e) {
            $error = ['status'=>false,'code'=>$e->getCode(),'msg'=>$e->getMessage(),'data'=>''];
            return json($error);
        }
    }

    /**
     * 修改角色域绑定关系
     * @param $id //绑定关系id
     * @param $domains_id //关系id
     * @param $roles_id //角色id
     * @param int $status //状态
     * @return \think\response\Json
     */
    public function domainsrolesedit($id,$domains_id,$roles_id,$status=1){
        try {
            $DomainsRolesRelationModel = new DomainsRolesRelationModel();
            $res = $DomainsRolesRelationModel->DomainsRolesEdit($id,$domains_id,$roles_id,$status);
            return json($res);
        } catch (\Exception $e) {
            $error = ['status'=>false,'code'=>$e->getCode(),'msg'=>$e->getMessage(),'data'=>''];
            return json($error);
        }
    }

    /**
     * 角色域绑定关系启用/禁用
     * @param $id
     * @param $status
     * @return \think\response\Json
     */
    public function domainsrolessetstatus($id,$status){
        try {
            $DomainsRolesRelationModel = new DomainsRolesRelationModel();
            $res = $DomainsRolesRelationModel->DomainsRolesSetStatus($id,$status);
            return json($res);
        } catch (\Exception $e) {
            $error = ['status'=>false,'code'=>$e->getCode(),'msg'=>$e->getMessage(),'data'=>''];
            return json($error);
        }
    }

    /**
     * 角色域绑定关系删除
     * @param $id
     * @return \think\response\Json
     */
    public function domainsrolesdel($id){
        try {
            $DomainsRolesRelationModel = new DomainsRolesRelationModel();
            $res = $DomainsRolesRelationModel->DomainsRolesDel($id);
            return json($res);
        } catch (\Exception $e) {
            $error = ['status'=>false,'code'=>$e->getCode(),'msg'=>$e->getMessage(),'data'=>''];
            return json($error);
        }
    }

}
